<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="关联项目" prop="inviteId">
						<el-select v-model="form.inviteId" clearable filterable remote :remote-method="remoteMethod" style="width: 100%" placeholder="项目名称、编号">
							<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="投标企业" prop="entId">
						<el-select v-model="form.entId" clearable filterable remote :remote-method="remoteMethod1" style="width: 100%" placeholder="输入公司名称、或统一信用代码、公司编号进行查询选择">
							<el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="中标金额" prop="amount">
						<el-input v-model="form.amount" placeholder="中标金额" clearable type="number">
							<template #append>
								元
							</template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="中标日期" prop="occurTime">
						<el-date-picker v-model="form.occurTime" placeholder="开始时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="投标评分" prop="score">
						<el-input v-model="form.score" placeholder="投标评分" clearable type="number">
							<template #append>
								分
							</template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="开标单位" prop="sendOrg">
						<el-input v-model="form.sendOrg" placeholder="开标单位" clearable maxlength="50"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明" prop="remark">
				<el-input v-model="form.remark" placeholder="备注说明" clearable maxlength="380" type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
export default {
	emits: ['success', 'closed'],
	components: {
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			mode: "add",
			titleMap: {
				add: '发布开标信息',
				edit: '编辑开标信息',
			},
			options: [],
			options1: [],
			form: {
				recordId:'',
				inviteId: '',
				entId: "",
				amount:0,
				occurTime: '',
				score: '',
				remark:'',
				sendOrg:''
			},
			rules: {
				inviteId: [
					{required: true, message: '关联项目不能为空', trigger: 'blur'}
				],
				entId: [
					{required: true, message: '中标企业不能为空', trigger: 'blur'}
				],
				amount: [
					{required: true, message: '中标金额不能为空', trigger: 'blur'}
				],
				occurTime:[
					{required: true, message: '中标日期不能为空', trigger: 'blur'}
				],
			}
		}
	},
	mounted() {
		this.remoteMethod("");
		this.remoteMethod1("");
	},
	methods: {
		async remoteMethod(query){
			let res = await this.$API.invite.inviteRecord.getInviteRecordListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options = res.data
			}
		},
		async remoteMethod1(query){
			let res = await this.$API.invite.inviteEnt.getInviteEntListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options1 = res.data
			}
		},
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.invite.inviteOpen.insertInviteOpen.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.invite.inviteOpen.updateInviteOpen.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		addNewFile(res, file)
		{
			let tArr = this.form.attachId.split(",");
			tArr.push(res.data.attachId);
			this.form.attachId = tArr.join(",");
		},
		setData(data) {
			this.form.recordId = data.recordId
			this.form.inviteId = data.inviteId
			this.form.entId = data.entId
			this.form.amount = data.amount
			this.form.occurTime = data.occurTime
			this.form.score = data.score
			this.form.remark = data.remark
			this.form.sendOrg = data.sendOrg
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
